package com.estudy.controller;

import com.estudy.domain.Result;
import com.estudy.domain.User;
import com.estudy.exception.LoginException;
import com.estudy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author laisir
 * @date 2024/8/28
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @Value("${jwt.tokenHead}")
    private String tokenHead;

    @PostMapping("/login")
    public Result<?> login(@RequestBody User user) {
        String token = userService.login(user);
        Map<String, Object> tokenMap = new HashMap<>();
        tokenMap.put("token", token);
        tokenMap.put("tokenHead", tokenHead);
        tokenMap.put("state", true);
        return Result.success(tokenMap);
    }
}
